{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>用户列表</legend>
    </fieldset>
    <div class="demoTable">
        <form class="layui-form layui-form-pane">
            <div class="layui-form-item" >
                <label class="layui-form-label"><h3 style="color: #009688;font-size: 18px">用户名:</h3></label>
                <div class="layui-input-inline" >
                    <input class="layui-input" name="username" id="username" placeholder="{:lang('pleaseEnter')}用户名">
                </div>
                <label class="layui-form-label"><h3 style="color: #009688;font-size: 18px">电话:</h3></label>
                <div class="layui-input-inline" >
                    <input class="layui-input" type="number" maxlength="11" name="tel" id="tel" placeholder="{:lang('pleaseEnter')}电话">
                </div>
                <label class="layui-form-label"><h3 style="color: #009688;font-size: 18px">性别:</h3></label>
                <div class="layui-input-inline" >
                    <select  name="sex" id="sex"  class="layui-input" style="font-size: 15px">
                        <option selected value="0">全部</option>
                        <option value="1" >男</option>
                        <option value="2" >女</option>
                    </select>
                </div>
                <button class="layui-btn" lay-submit=""  lay-filter="search" id="search" data-type="reload">搜索</button>
                <a onclick="javascript:window.location.reload();" class="layui-btn  layui-btn-warm"> 刷 新 </a>
            </div>
        </form>
    </div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>

<script type="text/html" id="user_status">
    {{# if(d.status == 1 ){ }}
    <span style="color: #0d8318">正常</span>
    {{# }else{  }}
    {{# if(d.status == 2 ){ }}
    <span style="color: #cfa20e">冻结</span>
    {{# }else{  }}
    <span style="color: #7b0a0d">删除</span>
    {{# } }}
    {{# } }}
</script>

<script type="text/html" id="barDemo">
    {{# if(d.status == 1 ){ }}
    <a href="#" class="layui-btn layui-btn-xs layui-btn-warm" lay-event="lock">冻结用户</a>
    <a href="#" class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">{:lang('del')}</a>
    {{# }else{  }}
    <a href="#" class="layui-btn layui-btn-xs" lay-event="recover">恢复</a>
    {{# } }}
</script>

<script type="text/html" id="topBtn">
    <a href="{:url('userAdd')}" class="layui-btn">{:lang('add')}</a>
</script>

</body>
{include file="common/foot"/}
<script>
    var $;
    var page_current =0;
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery, treeGrid = layui.treeGrid;
        var tableIn = table.render({
            elem: '#list',
            url: '{:url("userList")}',
            method:'post',
            toolbar: '#topBtn',
            title:'标准{:lang("list")}',
            page:true,
            cols: [[
                {field:'id', title: 'ID',align:"center", width:80,fixed: true}
                ,{field:'username', align:"center",title: '用户名', width:180}
                ,{field:'status', align:"center",title: '用户状态', width:180,templet:"#user_status"}
                ,{fixed:"right",width:460, align:'center',title:'操作',toolbar: '#barDemo'}
            ]],
            done:function(data,page,count){
                page_current = page;
            },
            limit:10,
        });

        table.on('tool(list)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('{:lang("Are you sure you want to delete it")}', function(index){
                    $.post("{:url('userStatus')}",{id:data.id,status:3},function(res){
                        if(res.code==1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
            if(obj.event === 'lock'){
                layer.confirm('确定要冻结该用户么？', function(index){
                    $.post("{:url('userStatus')}",{id:data.id,status:2},function(res){
                        if(res.code==0){
                            tableIn.reload(
                                {
                                    page: {curr: page_current},
                                    where: {
                                    }
                                }
                            )
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }

            if(obj.event === 'recover'){
                layer.confirm('确定恢复该评论么?', function(index){
                    $.post("{:url('userStatus')}",{id:data.id,status:1},function(res){
                        if(res.code==0){
                            tableIn.reload(
                                {
                                    page: {curr: page_current},
                                    where: {
                                    }
                                }
                            )
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });

        $(document).keyup(function(event){
            if(event.keyCode ==13){
                $("#search").trigger("click");
            }
        });
        //搜索
        form.on("submit(search)",function (data) {
            tableIn.reload({ page: {curr: page_current},where: data.field});
            return false;
        });
    });
</script>
</html>